namespace Blog2025.Application.Common;

public class ApiResult
{
    public int Code { get; set; } // 0=成功，非0=业务错误
    public string Message { get; set; } = "";
    public object? Data { get; set; }

    public static ApiResult Success(object? data = null, string? message = null)
        => new ApiResult { Code = 1000, Message = message ?? "操作成功", Data = data };

    public static ApiResult Fail(int code, string message)
        => new ApiResult { Code = code, Message = message };
}


/// <summary>
/// 泛型API结果类
/// </summary>
/// <typeparam name="T">数据类型</typeparam>
public class ApiResult<T>
{
    public int Code { get; set; } // 1000=成功，非1000=业务错误
    public string Message { get; set; } = "";
    public T? Data { get; set; }
    public bool Succeeded => Code == 1000;

    public static ApiResult<T> Success(T? data = default, string? message = null)
        => new ApiResult<T> { Code = 1000, Message = message ?? "操作成功", Data = data };

    public static ApiResult<T> Failed(string message, int code = 400)
        => new ApiResult<T> { Code = code, Message = message };

    public static ApiResult<T> Failed(int code, string message)
        => new ApiResult<T> { Code = code, Message = message };
}